*===============================================================================
/* Replication code for
“The Impact of Retail E-Commerce on Relative Prices and Consumer Welfare” 
by Yoon Jo, Misaki Matsumura, and David Weinstein

Please read README.pdf before running this program.
Be sure to make changes to the global macros "terminal" below.
*/
*===============================================================================
*** Preliminary set up
clear
set more off
set type double
set matsize 11000

*===============================================================================
* !!!!!    USER INPUT !!!!!!
* Specify Location of Project Folders
* Note: this should be the path to the folder "For_Distribution"
*
global terminal 	 "C:\Users\yoonjo\Downloads\dataverse_files (4)\For_Distribution"

*===============================================================================
*** Direcroty set up
global Code       	"$terminal/1.Code"
global Data       	"$terminal/2.Data"
global output       "$terminal/3.Output"
global table		"$terminal/3.Output/table"
cap mkdir "$terminal/3.Output/figure"
global figure		"$terminal/3.Output/figure"

*===============================================================================
*load do files
*===============================================================================
cd "$Code"
do 1_pricereg
do 2_pricereg_PW
do 3_pricereg_by_prefecture

*===============================================================================
* Main results
*===============================================================================
pre_est_ready /*dataready*/

plotfigure1 /*Figure 1*/
table1 /*Table 1*/
	
* Prepare datasets for analyses
forvalues y1 = 1991/2015{
	local y2 `=`y1'+1'
	est_ready `y1' `y2'
}
	est_ready 1991 1996
	est_ready 1996 2001
	est_ready 2001 2006
	est_ready 2006 2011
	est_ready 2011 2016
	
data_fig2_3 /* dataready for Figure 2-3*/

plotfigure2 /*plot Figure 2*/
plotfigure3 /*plot Figure 3*/
plotfigure4 /*Figure 4*/
	
table2 /*Table2*/
	
relative_price_change x_NS2009 d_1997 3 /*Table3 and Table5*/
relative_price_change x_NS2009 METI_size 4 /*Table4*/
		
reg_dind_base x_NS2009 d_1997 2sls 6 /*Table6 */
reg_dind_base x_NS2009 METI_size 2sls 7 /*Table7*/
	
reg_dind_extendperiod x_NS2009 d_1997 2sls 8 /*Table8*/
		
variety_gain /*Figure 5 and Table 9*/
	
	
*===============================================================================
* Appendix
*===============================================================================

plotfigure_a1 /*plot figure A.1*/

reg_dind_base x_NS2009 d_1997 ols _a3 /*Table A.3*/
reg_dind_extendperiod x_NS2009 d_1997 ols _a4 /*Table A.4*/

/*Use Proprietary data*/
*relative_price_change x_rakuten d_1997 _a5 /*Proprietary data: table A.5 and A.6*/
*plotfigure_a2 /*Proprietary data: plot figure A.2*/
*reg_dind_base x_rakuten d_1997 2sls _a7 /*Proprietary data: table A.7*/
*reg_dind_extendperiod x_rakuten d_1997 2sls _a8 /*Proprietary data: table A.8*/

/*A.3 Parsley and Wei (1996) Specification*/	
* Prepare datasets for analyses
forvalues y1 = 1991/2015{
	local y2 `=`y1'+1'
	est_ready_PW `y1' `y2'
}
	est_ready_PW 1991 1996
	est_ready_PW 1996 2001
	est_ready_PW 2001 2006
	est_ready_PW 2006 2011
	est_ready_PW 2011 2016
	
reg_dind_base_PW x_NS2009 d_1997 a1 /*table A.1*/
reg_dind_base_PW x_NS2009 METI_size a2  /*table A.2*/

/*A.6 Prefecture-level analysis*/		
*Prepare datasets for analyses
forvalues y1 = 1991/2015{
	local y2 `=`y1'+1'
	est_ready_pf `y1' `y2'
}
	est_ready_pf 1992 1996
	est_ready_pf 1996 2000
	est_ready_pf 2000 2006
	est_ready_pf 2006 2010
	est_ready_pf 2010 2014

relative_price_change_pf x_NS2014 d_1997 a9 /*table A.9*/
reg_dind_base_pf x_NS2014 d_1997 a10 /*table A.10*/
	
